#include <REGX52.H>
#include "Delay.H"
#include "Timer0_1ms.H"

unsigned char cha  = 0;

sbit SER   = P3^4;
sbit RCK   = P3^5;
sbit SRCLK = P3^6;



void _74HC595_WriteByte_(unsigned char Byte)
{
	unsigned char i = 0;
	
	for(i = 0 ; i < 8 ; i++)
	{
		SER = Byte & (0x80 >> i);
		SRCLK = 1;
		SRCLK = 0;
	}
	
	RCK = 1;
	RCK = 0;
	
}

void MatrixLED_Show(unsigned char ROW, unsigned int COL)
{
	_74HC595_WriteByte_(ROW);
	
	
	
	P0 = ~(0X80 >> COL);
	
	Delay(1);
	
	P0 = 0XFF;
	
}

void main()
{
	
		
	unsigned char code arr[96] = { 0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,							
							       0x00,0x00,0x08,0x38,0x1C,0x10,0x00,0x00,
								   0x00,0x20,0x12,0x1C,0x38,0x48,0x04,0x00,
							       0x20,0x10,0x09,0x3A,0x5C,0x90,0x08,0x04,
								   0x70,0x09,0x1D,0x7D,0xBE,0x9C,0x90,0x0E,
								   0xE1,0x11,0x3D,0x3E,0x7C,0xBC,0x88,0x87,
								   0xF9,0x7F,0x7F,0xFF,0xFF,0xFE,0xFE,0x9F,
								   0xE1,0x11,0x3D,0x3E,0x7C,0xBC,0x88,0x87,
								   0x70,0x09,0x1D,0x7D,0xBE,0x9C,0x90,0x0E,
								   0x20,0x10,0x09,0x3A,0x5C,0x90,0x08,0x04,
								   0x00,0x20,0x12,0x1C,0x38,0x48,0x04,0x00,
								   0x00,0x00,0x08,0x38,0x1C,0x10,0x00,0x00}; 
	SRCLK = 0;
	RCK   = 0;
	
	
	Timer0_Init();
	
	while(1)
	{	
			MatrixLED_Show( arr[(cha+0)%96], 0); // 因为P0口是扫描显示，所以第一列显示什么完全由ROW行控制，
			MatrixLED_Show( arr[(cha+1)%96], 1); // 用数组装要显示的列的点，cha+1后就向右移动了一格。
			MatrixLED_Show( arr[(cha+2)%96], 2); 
			MatrixLED_Show( arr[(cha+3)%96], 3); 
			MatrixLED_Show( arr[(cha+4)%96], 4); 
			MatrixLED_Show( arr[(cha+5)%96], 5); 
			MatrixLED_Show( arr[(cha+6)%96], 6); 
			MatrixLED_Show( arr[(cha+7)%96], 7); 	
			
		
	}
}

void Timer0_Rountine(void) interrupt 1
{
	static unsigned int count = 0; //计次
	
	TL0 = 0x66;				
	TH0 = 0xFC;	
	
	
	count++;
	
	if(count >= 500)
	{
		cha += 8;
		
		if(cha >= 96)
		{
			cha = 0;
			
		}
		
		count = 0;
	
	}
		
}

